home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SATAN11.ZIP / SRC / PORT_SCA / MALLOCS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-04  |  781 b   |  45 lines

  1.  /*
  2.   * mymalloc, myrealloc, dupstr - memory allocation with error handling
  3.   * 
  4.   * Environment: POSIX, ANSI
  5.   * 
  6.   * Author: Wietse Venema.
  7.   */
  8.  
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12.  
  13. #include "lib.h"
  14.  
  15. /* mymalloc - allocate memory or bust */
  16.  
  17. char   *mymalloc(len)
  18. int     len;
  19. {
  20.     char   *ptr;
  21.  
  22.     if ((ptr = malloc(len)) == 0)
  23.     error("Insufficient memory: %m");
  24.     return (ptr);
  25. }
  26.  
  27. /* myrealloc - reallocate memory or bust */
  28.  
  29. char   *myrealloc(ptr, len)
  30. char   *ptr;
  31. int     len;
  32. {
  33.     if ((ptr = realloc(ptr, len)) == 0)
  34.     error("Insufficient memory: %m");
  35.     return (ptr);
  36. }
  37.  
  38. /* dupstr - save string to heap */
  39.  
  40. char   *dupstr(str)
  41. char   *str;
  42. {
  43.     return (strcpy(mymalloc(strlen(str) + 1), str));
  44. }
  45.